home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Christina Milan AM to PM
/
Christina Milan - AM to PM.iso
/
christin.dir
/
00019_Script_Waft
< prev
next >
Wrap
Text File
|
2001-08-09
|
13KB
|
449 lines
-- DESCRIPTION --
on getBehaviorDescription me
return "¼
WAFT"&RETURN&RETURN&"¼
Makes a sprite rise up the screen like a bubble, rotating first one way then ¼
the other and vibrating horizontally as it rises. The movement is somewhat ¼
random."&RETURN&RETURN&"¼
By placing the surface below the starting height of the sprite, ¼
the same movement can be used to animate a falling leaf."&RETURN&RETURN&"¼
The sprite will stop moving once it reaches the 'surface'. At this moment it ¼
will send a custom '#WaftBehavior_Done message to all sprites. You can use¼
this message to trigger actions on other sprites, or to modify the current ¼
sprite. See the example in the Notes for Developers."&RETURN&RETURN&"¼
If you want random movement that continues indefinitely, use the ¼
'Random Movement and Rotation' behavior instead."&RETURN&RETURN&"¼
PERMITTED MEMBER TYPES:"&RETURN&PermittedMemberTypes (me)&RETURN&RETURN&"¼
* Number of degrees to rotate in each frame"&RETURN&"¼
* Maximum number of frames to rotate in each direction"&RETURN&"¼
* Maximum horizontally pixel shift in each frame"&RETURN&"¼
* Maximum number of frames to move in each direction"&RETURN&"¼
* Number of frames taken to reach the surface"&RETURN&"¼
* Height of the surface"
end getBehaviorDescription
on getBehaviorTooltip me
return"¼
Use with Bitmap, Flash and"&RETURN&"¼
Vector Shape members."&RETURN&RETURN&"¼
Imitate the movement of"&RETURN&"¼
a rising bubble or a"&RETURN&"¼
falling leaf."
end getBehaviorTooltip
-- NOTES FOR DEVELOPERS --
-- The Move handler activated on each prepareFrame. This calls three
-- other handlers: ChangeLevel, Turn and Shift. Each of these deals with
-- an independent movement.
--
-- The three properties myRemainingFrames, myTurnCounter and myShiftCounter
-- determine how many frames each movement varies over. When myRemainingFrames
-- reaches zero the behavior halts. It sends a WaftBehavior_Done call to
-- all sprites.
--
-- For example, you could place a behavior on the same sprite to swap the image
-- of the rising bubble with a (non-looping) film loop of a bursting bubble and
-- play a popping sound:
--
-- on WaftBehavior_Done me
-- sprite (me.spriteNum).member = member "Bubble bursting"
-- puppetSound 1, "Pop"
-- end
-- PUBLIC METHODS
-- This behavior supports the following external calls. See the handlers
-- themselves for details and copy-and-paste examples.
--
-- * Waft_Reset me, propertyList
-- * Waft_GetReference me, theList
-- HISTORY --
-- 28 September 1998: written for the D7 Behaviors Palette by James Newton
-- 23 November 1998: randomness and public methods added, descriptions revised.
-- PROPERTIES --
property spriteNum
property mySprite
-- error checking
property getPDLError
-- author-defined parameters
property myAnglePerFrame
property myTurnFrames
property myHShiftPerFrame
property myShiftFrames
property myTotalFrames
property mySurfaceHeight
-- internal properties
property myInitialLoc
property myRemainingFrames
property myRotation
property myTurnCounter
property myDirection
property myShiftCounter
property myDoneFlag
-- EVENT HANDLERS --
on beginSprite me
Initialize me
end beginSprite
on prepareFrame me
if myRemainingFrames then
Move me
else if myDoneFlag then
SendCustomEvent me
end if
end prepareFrame
-- CUSTOM HANDLERS --
on Initialize me -- sent by beginSprite
mySprite = sprite(me.spriteNum)
-- Error checking
memberType = mySprite.member.type
if not PermittedMemberTypes(me).getPos(memberType) then
ErrorAlert (me, #invalidMemberType, memberType)
end if
-- End of error checking
myInitialLoc = mySprite.loc
myRemainingFrames = myTotalFrames
myDoneFlag = TRUE
myTurnCounter = myTurnFrames
myShiftCounter = myShiftFrames
end Initialize
on Move me -- sent by prepareFrame
ChangeLevel me
Turn me
Shift me
end Move
on ChangeLevel me -- sent by Move
currentV = mySprite.locV
remainingV = currentV - mySurfaceHeight
deltaV = remainingV / myRemainingFrames
newV = currentV - deltaV
mySprite.locV = newV
myRemainingFrames = myRemainingFrames - 1
end ChangeLevel
on Turn me -- sent by Move
if not myTurnCounter then
myRotation = not myRotation
myTurnCounter = random (myTurnFrames)
end if
myTurnCounter = myTurnCounter - 1
if myRotation then
newAngle = mySprite.rotation + myAnglePerFrame
else
newAngle = mySprite.rotation - myAnglePerFrame
end if
mySprite.rotation = newAngle
end Turn
on Shift me -- sent by Move
if not myShiftCounter then
myDirection = not myDirection
myShiftCounter = random (myShiftFrames)
end if
myShiftCounter = myShiftCounter - 1
if myDirection then
mySprite.locH = mySprite.locH + myHShiftPerFrame
else
mySprite.locH = mySprite.locH - myHShiftPerFrame
end if
end Shift
on SendCustomEvent me -- sent by prepareFrame
myDoneFlag = FALSE
sendAllSprites (#WaftBehavior_Done, spriteNum, me)
end SendCustomEvent
-- PUBLIC METHODS --
on Waft_Reset me, propertyList
-- Allows you to rest the behavior on the fly. "propertyList" should be void
-- or contain any or all of the following properties (acceptable value types
-- are shown in parentheses):
-- #anglePerFrame (#integer | #float)
-- #turnFrames (#integer | #float)
-- #hShiftPerFrame (#integer | #float)
-- #shiftFrames (#integer | #float)
-- #totalFrames (#integer | #float)
-- #surfaceHeight (#integer | #float)
-- #startLoc (#point)
-- Apart from #startLoc, all these correspond to the properties set in the
-- Behavior Parameters dialog. Any other properties or value types will be
-- ignored. If "propertyList" is void, the behavior will restart with
-- its initial parameters.
--
-- Examples:
--
-- sendAllSprites (#Waft_Reset)
--
-- sendSprite (1, #Waft_Reset, [#turnFrames: 9, #totalFrames: random (60)])
--
-- waftRefList = sendAllSprites (#Waft_GetReference, [])
-- call (#Waft_Reset, waftRefList, [#totalFrames: 20 , #surfaceHeight: 12])
--
-- To play the behavior as a loop, add this behavior to the same sprite:
-- on WaftBehavior_Done me
-- call (#Waft_Reset, sprite(the currentSpriteNum).scriptInstanceList)
-- end
unchangedProps = [#totalFrames, #startLoc]
if not voidP (propertyList) then
if ilk (propertyList) = #propList then
i = propertyList.count()
repeat while i
theProp = propertyList.getPropAt(i)
theValue = propertyList[i]
case theProp of
#anglePerFrame:
case ilk (theValue) of
#integer, #float:
myAnglePerFrame = theValue
propertyList.deleteAt(i)
end case
#turnFrames:
case ilk (theValue) of
#integer, #float:
myTurnFrames = abs (integer (theValue))
propertyList.deleteAt(i)
end case
#hShiftPerFrame:
case ilk (theValue) of
#integer, #float:
myHShiftPerFrame = abs (integer (theValue))
propertyList.deleteAt(i)
end case
#shiftFrames:
case ilk (theValue) of
#integer, #float:
myShiftFrames = abs (integer (theValue))
propertyList.deleteAt(i)
end case
#totalFrames:
case ilk (theValue) of
#integer, #float:
myRemainingFrames = abs (integer (theValue))
propertyList.deleteAt(i)
end case
#surfaceHeight:
case ilk (theValue) of
#integer, #float:
mySurfaceHeight = abs (integer (theValue))
propertyList.deleteAt(i)
end case
#startLoc:
if ilk (theValue) = #point then
mySprite.loc = theValue
propertyList.deleteAt(i)
end if
end case
unchangedProps.deleteOne(theProp)
i = i - 1
end repeat
if propertyList.count() then
-- Return list of invalid properties
return propertyList
end if
else
return #invalidPropList
end if
end if
-- Reuse unchanged values
if unChangedProps.getPos (#startLoc) then
mySprite.loc = myInitialLoc
end if
if unChangedProps.getPos (#totalFrames) then
myRemainingFrames = myTotalFrames
end if
myDoneFlag = TRUE
end Waft_Reset
on Waft_GetReference me, theList
-- Returns a reference to the current behavior. theList is an optional
-- parameter. Use an empty list in a sendAllSprites call to return a
-- list of all Waft behaviors in the current frame. Use an empty linear list
-- to obtain a list of behaviors, or an empty property list to return a
-- list with sprite numbers as the properties and behavior references as
-- the values. Examples :
--
-- put sendAllSprites (#Waft_GetReference, [])
-- -- [<offspring "Waft" 2 2f1b594>, <offspring "Waft" 2 2f0dac0>]
--
-- put sendAllSprites (#Waft_GetReference, [:])
-- -- [1: <offspring "Waft" 2 2f1b594>, 2: <offspring "Waft" 2 2f0dac0>]
--
-- if you leave "theList" void, then the handler will return a reference to
-- the behavior on the given sprite (using sendSprite) or the highest sprite
-- with the behavior (using sendAllSprites). Examples:
--
-- put sendSprite (1, #Waft_GetReference)
-- -- <offspring "Waft" 2 2f1b594>
--
-- put sendAllSprites (#Waft_GetReference)
-- -- <offspring "Waft" 2 2f0dac0>
case ilk (theList) of
#list: theList.append(me)
#propList: theList.addProp(me.spriteNum, me)
otherwise
return me
end case
return theList
end Waft_GetReference
-- ERROR CHECKING --
on ErrorAlert me, theError, data
-- sent by getPropertyDescriptionList, Initialize
case theError of
#getPDLError:
alert "¼
Error: This behavior works only with the following members types: "&¼
permittedMemberTypes(me)&RETURN&RETURN&"¼
Hit OK and then delete this behavior from the sprite."&RETURN&"¼
For more information on deleting Behaviors, see the Help system."
if the optionDown then
return ¼
[ ¼
#getPDLError: ¼
[ ¼
#comment: "ERROR: Wrong member type. Click 'Cancel'.", ¼
#format: #string, ¼
#range: [""], ¼
#default: "" ¼
] ¼
]
end if
otherwise
-- Determine the behavior's name
behaviorName = string (me)
delete word 1 of behaviorName
delete the last word of behaviorName
delete the last word of behaviorName
-- Convert #data to useful value
case data.ilk of
#void: data = "<void>"
#symbol: data = "#"&data
end case
case theError of
#invalidMemberType:
alert "¼
BEHAVIOR ERROR: Frame "&the frame&", Sprite "&me.spriteNum&RETURN&RETURN&"¼
Behavior "&behaviorName&" only functions with the following member types:"&¼
RETURN&permittedMemberTypes()&RETURN&RETURN&¼
"Current type = "&data
halt
end case
end case
end ErrorAlert
-- AUTHOR-DEFINED PARAMETERS --
on getPropertyDescriptionList me
if not the currentSpriteNum then exit
-- Error check: does current sprite contain appropriate member type?
theMember = sprite(the currentSpriteNum).member
memberType = theMember.type
permittedTypes = PermittedMemberTypes(me)
if not permittedTypes.getPos(memberType) then
return errorAlert (me, #getPDLError, permittedTypes)
end if
return ¼
[ ¼
#myAnglePerFrame: ¼
[ ¼
#comment: "Angle to rotate in each frame:", ¼
#format: #float, ¼
#default: 10 ¼
], ¼
#myTurnFrames: ¼
[ ¼
#comment: "Maximum frames to rotate in each direction:", ¼
#format: #Integer, ¼
#default: 10 ¼
], ¼
#myHShiftPerFrame: ¼
[ ¼
#comment: "Maximum horizontal shift in each frame:", ¼
#format: #integer, ¼
#default: 10 ¼
], ¼
#myShiftFrames: ¼
[ ¼
#comment: "Maximum frames to shift in each direction:", ¼
#format: #Integer, ¼
#default: 10 ¼
], ¼
#myTotalFrames: ¼
[ ¼
#comment: "Number of frames to reach the surface:", ¼
#format: #Integer, ¼
#default: 60 ¼
], ¼
#mySurfaceHeight: ¼
[ ¼
#comment: "Height of surface (pixels from top of stage):", ¼
#format: #integer, ¼
#default: 0¼
] ¼
]
end getPropertyDescriptionList
on PermittedMemberTypes me
-- sent by:
-- getBehaviorDescription
-- getPropertyDescriptionList
-- Initialize
-- ErrorAlert
return [#bitmap, #flash, #vectorShape]
end PermittedMemberTypes